package lab12;

class AllWork {

	private static final int MAX_TASKS = 15;
	
	private Task[] tasks;
	private int freePlacesForTasks;
	private int currentUnassignedTask;

	AllWork() {
		tasks = new Task[MAX_TASKS];
		freePlacesForTasks = MAX_TASKS;
		currentUnassignedTask = -1;
	}
	
	void addTask(Task task) {
		if (task != null && freePlacesForTasks > 0) {
			tasks[numberOfAddedTasks()] = task;
			freePlacesForTasks--;
		}
	}
	
	Task getNextTask() {
		if ( currentUnassignedTask+1 >= numberOfAddedTasks())
			return null;
		
		++currentUnassignedTask;
		return tasks[currentUnassignedTask];
	}

	/**
	 * @return
	 */
	private int numberOfAddedTasks() {
		return MAX_TASKS - freePlacesForTasks;
	}
	
	boolean isAllWorkDone() {
//		for ( int task=0; task < numberOfAddedTasks(); task++ ){
//			if ( tasks[task].getWorkingHours() != 0 )
//				return false;
//		}
		for ( Task task : tasks ) {
			if (task!=null && task.getWorkingHours() != 0 )
				return false;
		}
		return true;
	}
}